package com.base.utils;

import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.UUID;

/**
 * Created by Android on 2017/3/7 0007.
 */

public class DeviceInfo {

    private Context context;
    public static DeviceInfo instance;
    private DeviceInfo(Context context) {
        this.context = context;
        instance = this;
    }

    public static void init(Context c) {
        new DeviceInfo(c);
    }

    private static String deviceId;
    public static String getDeviceInfo(Context context) {
        if (deviceId != null)
            return deviceId;

        TelephonyManager tel = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        try {
            deviceId = tel.getDeviceId();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (deviceId == null) {
            deviceId = instance.getAndroidId();
        }
        return deviceId;
    }

    private String getAndroidId() {
        return android.provider.Settings.Secure.getString(
                context.getContentResolver(),
                android.provider.Settings.Secure.ANDROID_ID);
    }

    public static String getUUID() {
        return UUID.randomUUID().toString();
    }
}
